package io.github.talelin.latticy.controller.v1;


import com.baomidou.mybatisplus.core.metadata.IPage;
import io.github.talelin.core.annotation.LoginRequired;
import io.github.talelin.core.annotation.PermissionMeta;
import io.github.talelin.latticy.common.util.PageUtil;
import io.github.talelin.latticy.dto.putaway.PutAwayDTO;
import io.github.talelin.latticy.dto.putaway.PutAwayPageDTO;
import io.github.talelin.latticy.dto.putaway.PutAwaySkuDTO;
import io.github.talelin.latticy.dto.stock.BatchStockDTO;
import io.github.talelin.latticy.model.PutAwayDO;
import io.github.talelin.latticy.service.PutAwayService;
import io.github.talelin.latticy.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Positive;

/**
 * 上架表前端控制器
 *
 * @author generator@wulongbo
 * @since 2022-06-29
 */
@RestController
@RequestMapping("/v1/putAway")
public class PutAwayController {

    @Autowired
    private PutAwayService putawayService;

    @LoginRequired
    @PermissionMeta(value = "新增上架记录")
    @PostMapping("/createPutAway")
    public CreatedVO putAway(@RequestBody @Validated PutAwayDTO putawayDto) {
        putawayService.putAwayInfo(putawayDto);
        return new CreatedVO();
    }

    @PutMapping("/{id}")
    public UpdatedVO update(@PathVariable @Positive(message = "{id.positive}") Integer id) {
        return new UpdatedVO();
    }

    @DeleteMapping("/{id}")
    public DeletedVO delete(@PathVariable @Positive(message = "{id.positive}") Integer id) {
        return new DeletedVO();
    }

    @GetMapping("/{id}")
    public PutAwayDO get(@PathVariable(value = "id") @Positive(message = "{id.positive}") Integer id) {
        return null;
    }

    @GetMapping("/page")
    public PageResponseVO<PutAwayVO> page(PutAwayPageDTO putAwayDTO) {
        IPage<PutAwayVO> putAwayDOIPage = putawayService.getPutAwayPage(putAwayDTO);
        return PageUtil.build(putAwayDOIPage);
    }

    @LoginRequired
    @PermissionMeta(value = "调整库龄时间")
    @PostMapping("/resizeLibraryAge")
    public UpdatedVO resizeLibraryAge(@RequestBody @Validated PutAwaySkuDTO putAwayDTO) {
        putawayService.resizeLibraryAge(putAwayDTO);
        return new UpdatedVO();
    }


    @LoginRequired
    @PermissionMeta(value = "调整库存数量")
    @PostMapping("/resizeStockNum")
    public UpdatedVO resizeStockNum(@RequestBody @Validated PutAwaySkuDTO putAwayDTO) {
        putawayService.resizeStockNum(putAwayDTO);
        return new UpdatedVO();
    }

    @LoginRequired
    @PermissionMeta(value = "移动库位")
    @PostMapping("/moveLocation")
    public UpdatedVO moveLocation(@RequestBody @Validated PutAwaySkuDTO putAwayDTO) {
        putawayService.moveLocation(putAwayDTO);
        return new UpdatedVO();
    }
}
